{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0680e9f3-7225-4f54-a5c7-984d8e92eaf3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据基本信息\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 20 entries, 0 to 19\n",
      "Data columns (total 9 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   学籍号     20 non-null     int64  \n",
      " 1   身高      20 non-null     int64  \n",
      " 2   体重      20 non-null     int64  \n",
      " 3   肺活量     20 non-null     int64  \n",
      " 4   50米跑    20 non-null     float64\n",
      " 5   立定跳远    20 non-null     int64  \n",
      " 6   坐位体前屈   20 non-null     float64\n",
      " 7   1000米跑  20 non-null     int64  \n",
      " 8   引体向上    20 non-null     int64  \n",
      "dtypes: float64(2), int64(7)\n",
      "memory usage: 1.5 KB\n",
      "数据全部内容信息\n",
      "\t学籍号\t身高\t体重\t肺活量\t50米跑\t立定跳远\t坐位体前屈\t1000米跑\t引体向上\n",
      "0\t12001060224\t173\t51\t2895\t7.9\t222\t9.5\t274\t14\n",
      "1\t12101060202\t173\t60\t3595\t6.9\t238\t1.0\t239\t5\n",
      "2\t12101060204\t169\t48\t3875\t7.2\t220\t6.6\t279\t9\n",
      "3\t12101060207\t176\t57\t4207\t7.1\t242\t1.0\t251\t10\n",
      "4\t12101060208\t170\t54\t5602\t7.8\t242\t10.0\t314\t11\n",
      "5\t12101060209\t175\t120\t5057\t8.9\t190\t1.0\t250\t0\n",
      "6\t12101060210\t174\t54\t4087\t7.0\t263\t6.1\t242\t11\n",
      "7\t12101060214\t174\t94\t4053\t7.7\t205\t3.6\t352\t0\n",
      "8\t12101060215\t179\t83\t4028\t7.8\t217\t14.1\t351\t2\n",
      "9\t12101060217\t183\t81\t4748\t7.4\t245\t3.0\t234\t3\n",
      "10\t12101060219\t170\t56\t3651\t6.9\t243\t6.8\t249\t14\n",
      "11\t12101060220\t174\t54\t4492\t6.8\t241\t19.5\t224\t14\n",
      "12\t12101060222\t174\t56\t3875\t6.6\t259\t1.0\t245\t18\n",
      "13\t12101060223\t177\t62\t4961\t7.0\t252\t16.5\t223\t15\n",
      "14\t12101060224\t175\t65\t4532\t7.2\t235\t15.6\t246\t10\n",
      "15\t12101060228\t171\t70\t4089\t7.2\t223\t12.0\t257\t11\n",
      "16\t12101060230\t171\t67\t3801\t7.7\t210\t14.8\t268\t1\n",
      "17\t12101060232\t165\t65\t4157\t7.2\t240\t17.0\t229\t14\n",
      "18\t12101060233\t172\t74\t4482\t8.0\t227\t10.9\t250\t11\n",
      "19\t12101060236\t180\t80\t3617\t8.3\t210\t4.0\t321\t1\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>成分1</th>\n",
       "      <th>成分2</th>\n",
       "      <th>学籍号</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.348174</td>\n",
       "      <td>-2.158853</td>\n",
       "      <td>12001060224</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.567295</td>\n",
       "      <td>-0.558163</td>\n",
       "      <td>12101060202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.546154</td>\n",
       "      <td>-1.521166</td>\n",
       "      <td>12101060204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.694333</td>\n",
       "      <td>0.433982</td>\n",
       "      <td>12101060207</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.226989</td>\n",
       "      <td>0.808259</td>\n",
       "      <td>12101060208</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>-4.494052</td>\n",
       "      <td>1.511711</td>\n",
       "      <td>12101060209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.779844</td>\n",
       "      <td>0.410512</td>\n",
       "      <td>12101060210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>-3.171955</td>\n",
       "      <td>-0.909297</td>\n",
       "      <td>12101060214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>-2.466072</td>\n",
       "      <td>-0.379711</td>\n",
       "      <td>12101060215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>-0.894266</td>\n",
       "      <td>2.454224</td>\n",
       "      <td>12101060217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1.776310</td>\n",
       "      <td>-0.924813</td>\n",
       "      <td>12101060219</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2.166182</td>\n",
       "      <td>0.679757</td>\n",
       "      <td>12101060220</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2.380719</td>\n",
       "      <td>0.109620</td>\n",
       "      <td>12101060222</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>1.876900</td>\n",
       "      <td>1.905867</td>\n",
       "      <td>12101060223</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.720742</td>\n",
       "      <td>0.729805</td>\n",
       "      <td>12101060224</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.428809</td>\n",
       "      <td>-0.464430</td>\n",
       "      <td>12101060228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>-1.038912</td>\n",
       "      <td>-1.175910</td>\n",
       "      <td>12101060230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>1.918214</td>\n",
       "      <td>-0.636294</td>\n",
       "      <td>12101060232</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>-0.273243</td>\n",
       "      <td>0.312643</td>\n",
       "      <td>12101060233</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>-3.092161</td>\n",
       "      <td>-0.627742</td>\n",
       "      <td>12101060236</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         成分1       成分2          学籍号\n",
       "0   0.348174 -2.158853  12001060224\n",
       "1   0.567295 -0.558163  12101060202\n",
       "2   0.546154 -1.521166  12101060204\n",
       "3   0.694333  0.433982  12101060207\n",
       "4   0.226989  0.808259  12101060208\n",
       "5  -4.494052  1.511711  12101060209\n",
       "6   1.779844  0.410512  12101060210\n",
       "7  -3.171955 -0.909297  12101060214\n",
       "8  -2.466072 -0.379711  12101060215\n",
       "9  -0.894266  2.454224  12101060217\n",
       "10  1.776310 -0.924813  12101060219\n",
       "11  2.166182  0.679757  12101060220\n",
       "12  2.380719  0.109620  12101060222\n",
       "13  1.876900  1.905867  12101060223\n",
       "14  0.720742  0.729805  12101060224\n",
       "15  0.428809 -0.464430  12101060228\n",
       "16 -1.038912 -1.175910  12101060230\n",
       "17  1.918214 -0.636294  12101060232\n",
       "18 -0.273243  0.312643  12101060233\n",
       "19 -3.092161 -0.627742  12101060236"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "excel_file = pd.ExcelFile('D:\\大学\\大三\\成绩\\体育成绩.xlsx')\n",
    "sheet_names = excel_file.sheet_names\n",
    "sheet_names\n",
    "df = excel_file.parse('体育成绩')\n",
    "print('数据基本信息')\n",
    "df.info()\n",
    "rows, columns = df.shape\n",
    "if rows < 50 and columns < 30:\n",
    "    print('数据全部内容信息')\n",
    "    print(df.to_csv(sep='\\t', na_rep='nan'))\n",
    "else:\n",
    "    print('数据前几行内容信息')\n",
    "    print(df.head().to_csv(sep='\\t', na_rep='nan'))\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.decomposition import PCA\n",
    "X = df.drop(columns=['学籍号'])\n",
    "scaler = StandardScaler()\n",
    "X_scaled = scaler.fit_transform(X)\n",
    "pca = PCA(n_components=2)\n",
    "X_pca = pca.fit_transform(X_scaled)\n",
    "pca_df = pd.DataFrame(data=X_pca, columns=['成分1','成分2'])\n",
    "pca_df['学籍号'] = df['学籍号']\n",
    "pca_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b89ab4f-c9b9-4ebb-871c-8d03de87d073",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
